import QtQuick 2.0
import QtQuick.Controls

Component{
    Rectangle{
        id:deviceCard
        color:"white"
        radius: 10
        anchors.fill: parent

        property string deviceName//: "默认设备"
        property string deviceState//: "在线"
        property string deviceIcon//: "qrc:/icon/icon/m_device.svg"
        signal deviceBtnClickSig(string deviceName,int state)

        Rectangle{
            anchors.fill: parent
            anchors.margins: 10
            color:"transparent"

            //名称及状态
            Text{
                id:deviceCardName
                anchors.top: parent.top
                anchors.horizontalCenter: parent.horizontalCenter
                text: deviceName
            }
            Text{
                id:deviceCardState
                anchors.top: deviceCardName.bottom
                anchors.horizontalCenter: parent.horizontalCenter
                text: deviceState
            }
            Image{
                id:deviceIcon
                anchors.centerIn: parent
                source: "qrc:/icon/icon/m_device.svg"
            }
            Button{
                id:deviceSwitchBtn
                anchors.bottom: parent.bottom
                anchors.horizontalCenter: parent.horizontalCenter
                width: parent.width
                height: parent.height / 4
                checkable: true

                Image{
                    anchors.centerIn: parent
                    source: "qrc:/icon/icon/switch.svg"
                    sourceSize.height: parent.height/3*2
                    sourceSize.width: parent.height/3*2
                }
                background: Rectangle{
                    radius: 10
                    color: deviceSwitchBtn.checked ? "blue":"grey"
                }
                onClicked:{
                    deviceBtnClickSig(deviceName,checked?1:0)
                }

            }
        }
    }
}
